package com.tomdd.iotdbapplication.config;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zx
 * @date 2025-04-08 13:51
 */
@Configuration
@Slf4j
// @EnableConfigurationProperties(IoTDBProperties.class)
public class IotDBConfig {

    @Resource
    private IoTDBProperties iotDBProperties;

    @Bean(destroyMethod = "close")
    public SessionPool sessionPool() throws IoTDBConnectionException {
        log.info("IoTDB session pool init start");
        return new SessionPool.Builder()
                .host(iotDBProperties.getHost())
                .port(iotDBProperties.getPort())
                .user(iotDBProperties.getUsername())
                .password(iotDBProperties.getPassword())
                .build();
    }

}
